<template>
<img src="../assets/jr.png" style=" position:relative;  position:absolute;z-index:-1;"/>
<el-container>
    <el-header></el-header>
    <el-main><div class="login">
    <el-form label-width="80px" :model="loginData">
      <h2>健康档案管理系统</h2>
      <el-form-item label="用户名">
        <el-input placeholder="请输入账号" v-model="loginData.name"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input
          placeholder="请输入密码"
          v-model="loginData.password"
          show-password
        ></el-input>
      </el-form-item>
    
    <el-form-item>
      <el-button @click="subFun" class="sub-btr" type="primary">登录</el-button>
    </el-form-item>
    </el-form>
  </div></el-main>
  </el-container>

  
</template>

<script>
import { reactive } from "vue";
import { ElMessage } from "element-plus";
import { login } from "../http/api";
import router from "../router/index.js";
export default {
  name: "Login",
  setup() {
    let loginData = reactive({
      name: "",
      password: "",
    });

    let subFun = () => {
      // 先判断账号密码是否为空
      if (!loginData.name || !loginData.password) {
        ElMessage.error("账号或密码为空");
        return;
      }
      //执行登录操作
      login(loginData).then((res) => {
        console.log(res);
        router.push("./Home");
      });
      return {};
    };

    return {
      loginData,
      subFun,
    };
  },
};
</script>

<style scoped>
h2 {
  text-align: center;
  color: rgb(255, 255, 255);
}
.login {
  width: 400px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
  margin: 150px auto;
  padding: 50px;
}
.sub-btr {
  width: 100%;
}

</style>
